#ifndef BLACKBEAR_H_
#define BLACKBEAR_H_

#include <QSqlDatabase>
#include <vector>

#include "BearFactory.h"

class SqlManager;
class Bear;

class BlackBear 
{
public:
	BlackBear();
	BlackBear( QSqlDatabase* dataBase, QString& connectionName );
	
	~BlackBear();

	//Save bear in database
	bool save( Bear& bear );

	//Delete bear in database
	bool deleteObject( Bear& bear );

	//Load a bear from database
	Bear* load( QString className, int objectId );

	//Load all bears from a table
	std::vector<Bear*> load( QString className );

	//Create all tables from the xml mapping file
	bool createTables( QString& xmlMappingFileClass );

private:
	int saveComposite( Bear& bear );
	
	bool isComposite( QString className  )
	{
		return m_factory->exist( className );
	}

	Bear* createBear( QString className )
	{
		return m_factory->createBear( className );
	}

	QSqlDatabase* m_dataBase;
	QString m_connectionName;
	BearFactory* m_factory;

	friend class SqlManager;
};

#endif /*BLACKBEAR_H_*/
